using System;
using System.Threading.Tasks;
using UMC.Data;
using UMC.Data.Caches;
using UMC.Net;

namespace UMC.Bridge;
public partial class SocksUser : Record
{

    static SocksUser()
    {
        SocksUserCache = new Data.Caches.Cache("ExpirationTime", 1200, new SocksUser(), "UserAgent", "Port", "ClientIP");
    }
    public static UMC.Data.Caches.Cache Cache => SocksUserCache;
    static UMC.Data.Caches.Cache SocksUserCache;
    public StringValue Port { get; set; }
    public StringValue ClientIP { get; set; }
    public StringValue Username { get; set; }
    public StringValue UserAgent { get; set; }

    public StringValue ActiveTime { get; set; }
    public StringValue ExpirationTime { get; set; }

    public StringValue SessionKey { get; set; }


        readonly static Action<SocksUser, object>[] _SetValues = new Action<SocksUser, object>[] { (r, t) => r.ActiveTime = Reflection.ParseObject(t, r.ActiveTime), (r, t) => r.ClientIP = Reflection.ParseObject(t, r.ClientIP), (r, t) => r.ExpirationTime = Reflection.ParseObject(t, r.ExpirationTime), (r, t) => r.Port = Reflection.ParseObject(t, r.Port), (r, t) => r.SessionKey = Reflection.ParseObject(t, r.SessionKey), (r, t) => r.UserAgent = Reflection.ParseObject(t, r.UserAgent), (r, t) => r.Username = Reflection.ParseObject(t, r.Username) };
        readonly static string[] _Columns = new string[] { "ActiveTime", "ClientIP", "ExpirationTime", "Port", "SessionKey", "UserAgent", "Username" };
        protected override void SetValue(string name, object obv)
        {
            var index = Utility.Search(_Columns, name, StringComparer.CurrentCultureIgnoreCase);
            if (index > -1) _SetValues[index](this, obv);
        }
        protected override void GetValues(Action<String, object> action)
        {
            AppendValue(action, "ActiveTime", this.ActiveTime);
            AppendValue(action, "ClientIP", this.ClientIP);
            AppendValue(action, "ExpirationTime", this.ExpirationTime);
            AppendValue(action, "Port", this.Port);
            AppendValue(action, "SessionKey", this.SessionKey);
            AppendValue(action, "UserAgent", this.UserAgent);
            AppendValue(action, "Username", this.Username);
        }

        protected override RecordColumn[] GetColumns()
        {
            var cols = new RecordColumn[7];
            cols[0] = RecordColumn.Column("ActiveTime", this.ActiveTime);
            cols[1] = RecordColumn.Column("ClientIP", this.ClientIP);
            cols[2] = RecordColumn.Column("ExpirationTime", this.ExpirationTime);
            cols[3] = RecordColumn.Column("Port", this.Port);
            cols[4] = RecordColumn.Column("SessionKey", this.SessionKey);
            cols[5] = RecordColumn.Column("UserAgent", this.UserAgent);
            cols[6] = RecordColumn.Column("Username", this.Username);
            return cols;
        }

}